import { Schema, model } from 'mongoose';

import type { IScriptGroup } from '../types';

const ScriptGroupSchema = new Schema<IScriptGroup>(
  {
    desc: {
      required: true,
      type: String,
    },
    parentId: {
      required: true,
      type: Schema.Types.ObjectId,
    },
    scripts: {
      default: [],
      type: [Schema.Types.ObjectId],
    },
    title: {
      required: true,
      type: String,
    },
  },
  {
    // 自动添加createdAt和updatedAt时间戳
    timestamps: true,
  },
);

export const ScriptGroupModel = model<IScriptGroup>('ScriptGroup', ScriptGroupSchema);
